
#include <ttg/all.h>
#include "Serial.h"
#include "Parallel.h"

using namespace ttg::pipeline;
using namespace ttg::utils;

int main()
{
	ttg::services::ServiceBase::getRef()->start();						//starting services.
	ParameterInt throw_count("throw_count", 10000, 5000000);			//count of throws for Pi calculation.
	throw_count = 100000;
	ParameterEnum core("Calculation core", "Serial|Parallel");			//type of calculation core.
	UtilManager::getRef()->addUtility("ParameterManager");
	while (true)
	{
		double pi;
		core.lock();													//locking parameter to avoid its change.
		double t_start = ttg::services::Timer::getRef()->getSeconds();
		if (core == core["Serial"])
			pi = serialPi(throw_count); else
		if (core == core["Parallel"])
			pi = parallelPi(throw_count);
		double t_end = ttg::services::Timer::getRef()->getSeconds();
		core.unLock();													//unlocking parameter.
		printf("Calculated Pi: %lf, precision: %lf, elasped time: %lf\n",
				pi, fabs(pi - TTG_PI), t_end - t_start);
	}
	exit(0);
}
